export default Object.assign({}, {
  getOptions: function (options) { 
    const { chartData } = options
    const xAxis = {
      type: 'category',
      data: chartData?.labels
    }
    const legend = {
      data: chartData?.series.map(item => item.label)
    }
    const grid = {
      left: '2%',
      top: '12%',
      bottom: '2%'
    }
    const yAxis = {
      type: 'value',
      axisLabel: {
        formatter: (value) => (value * 100) + '%'
      }
    }
    const tooltip = {
      show: true,
      trigger: 'axis',
      valueFormatter: (value) => (value * 100).toFixed(2) + '%'
    }
    const series = chartData?.series.map(item => {
      return {
        name: item.label,
        type: 'line',
        label: {
          show:true,
          formatter: (params) => (params.value * 100).toFixed(2) + '%'
        },
        data: item.data,
        smooth: false 
      }
    })
    return { xAxis, yAxis,legend, series,tooltip, grid }
  },
  render: function (instance, options) {
    instance && instance.setOption(options, true)
    return instance
  },
})